<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>找回密码</title>
		<link rel="stylesheet" href="__CSS__/mui.min.css" />
		<link rel="stylesheet" href="__CSS__/iconfont.css" />
		<link rel="stylesheet" href="__CSS__/style.css" />
		<link rel="stylesheet" href="__CSS__/mall.css" />
	</head>

	<body style="background: #0ABC06;">
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">找回密码</h1>
		</header>
		<div class="mui-content login_con" style="height: 100%;">
			<div class="login_top"><img src="__IMG__/logo.png" class="mmp_index_img"></div>
			<form id='login-form' class="login_formbox">
				<div class="mui-input-row">
					<label><span class="iconfont icon-dianhua"></span></label>
					<input id='mobile' type="text" class="mui-input-clear mui-input" placeholder="请输入手机号码">
				</div>
				<div class="mui-input-row fl_yanzm">
					<div class="left clearfix">
						<label><span class="iconfont icon-yanzhengma"></span></label>
						<input id='code' type="text" class="mui-input-clear mui-input" placeholder="请输入验证码">
					</div>
					<a href="javascript:;" id="send_code" onclick="getCode()">获取验证码</a>
				</div>
				<div class="mui-input-row">
					<label><span class="iconfont icon-mima"></span></label>
					<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入新密码">
				</div>
			</form>
			<div class="mui-content-padded getpwd_btn">
				<button class="mui-btn mui-btn-block login_btn" id="btn">确 认 修 改</button>
			</div>
			<div class="link_area">
				<a id='return' href="javascript:;">返回登录</a>
			</div>
		</div>
	</body>

</html>
<script src="__JS__/mui.min.js"></script>
<script src="__JS__/jquery.min.js"></script>
<script src="__LIB__/layer.js"></script>
<script src="__JS__/index.js"></script>
<script type="text/javascript">
	//返回登录
	$("#return").click(function() {
		location.href = "{:url('index/login')}";
	});

	$('#btn').click(function() {
		var mobile = $("#mobile").val();
		var code = $("#code").val();
		var pwd = $("#password").val();
		if(mobile == '') {
			app.msg('手机号码不能为空');
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(mobile)) {
			app.msg("手机号码格式不正确");
			onoff = true;
			return;
		}
		if(code == '') {
			app.msg('验证码不能为空');
			return;
		}
		if(pwd == '') {
			app.msg('密码不能为空');
			return;
		}
		var reg = /^[a-zA-Z0-9]{6,16}$/; //验证规则
		if(!reg.test(pwd)) {
			app.msg('密码只能为英文和数字,且长度6-16位数');
			return;
		}
		$.ajax({
			url: "{:url('index/forget')}",
			type: 'post',
			data: {
				mobile: mobile,
				code: code,
				password: pwd
			},
			success: function(json) {
				app.ajax_msg(json);
			}
		})
	});

	var onoff = true;

	function getCode() {
		if(!onoff) {
			return;
		}
		onoff = false;
		var mobile = $("#mobile").val();
		if(mobile == "") {
			layer.msg("请输入手机号", {
				icon: 0
			});
			onoff = true;
			return;
		}
		var captcha = $("#captcha").val();
		if(captcha == "") {
			layer.msg("请输入图形验证码", {
				icon: 0
			});
			onoff = true;
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(mobile)) {
			layer.msg("手机号码格式不正确", {
				icon: 0
			});
			onoff = true;
			return;
		}
		var isdown = false;
		$.ajax({
			type: "post",
			url: "{:url('index/forget_code')}",
			data: {
				mobile: mobile,
				captcha: captcha
			},
			success: function(data) {
				if(data.code == 1) {
					var num = 60;
					var timer = setInterval(function() {
						num--;
						if(num == 0) {
							$("#send_code").html('获取中...');
							//定时器停了
							clearInterval(timer);
							onoff = true;
						} else {
							$("#send_code").html(num + "秒后可重发");
						}
					}, 1000); // 1000 毫秒==1秒
				} else {
					onoff = true;
				}
				layer.msg(data.msg, {
					icon: 0
				});
			}
		});
	}
</script>